home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_12
/
taylor
/
undrflow.cpp
< prev
Wrap
C/C++ Source or Header
|
1995-08-17
|
1KB
|
52 lines
// Fill input stream buffer
int gpibin::underflow()
{
int count,growth,inplimit;
char *temp;
// See if we have allocated a stream buffer yet
if(base_ == NULL)
{
gleng_ = 128; // a good starting length
base_ = new char[gleng_];
if(base_ == NULL)
{
cerr << "Can't allocate get stream buffer." << endl;
exit(1);
}
ebuf_ = base_ + gleng_;
}
inplimit = gleng_-1;
// Get entire gpib transfer
for(count=0;;)
{
::ibrd(device,base_+count,inplimit);
status = ibsta; // ibsta & ibcnt are NI globals
count += ibcnt;
if(status & (ERR|TIMO|END)) // Done if EOI or error
break;
growth = gleng_ >> 1;
temp = new char[gleng_ + growth];
if(temp == NULL)
{
cerr << "Can't increase get stream size." << endl;
exit(1);
}
// transfer to new area & release old area
memmove(temp,base_,gleng_);
delete base_;
base_ = temp;
inplimit = growth-1;
gleng_ += growth;
}
base_[count] = '\0';
if(base_[count-1] == '\n')
base_[--count] = '\0';
gptr_ = base_;
egptr_ = base_ + count; // Set pointer to end of get portion
return *gptr_;
}